<!DOCTYPE html> 
<html> 
<head>  
    <!--META-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.75">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">

    <!--CSS-->
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.structure.min.css" />
    <link rel="stylesheet" href="API/css/themes/default/jquery.mobile.theme.min.css" />
    <link rel="stylesheet" href="API/css/mycss.css" />
    <link rel="stylesheet" href="css/mycss.css" />

    <!--JS-->
    <script type="text/javascript" src="API/js/jquery.min.js"></script>
    <script type="text/javascript" src="API/js/jquery.mobile.min.js"></script>
    <!--<script type="text/javascript" src="API/js/highcharts.js"></script>-->
    <!--<script type="text/javascript" src="API/js/modules/exporting.js"></script>-->
    <!--<script type="text/javascript" src="API/js/jquery.dataTables.min.js"></script>--> 
    <script type="text/javascript" src="include/config.js"></script>
    <script type="text/javascript" src="API/js/fonctions.js"></script>
    <script type="text/javascript" src="js/fonctions.js"></script>

    <script language="javascript" type="text/javascript">
    checkMaintenance();
    checkAuthentification();
	
    ///////////////////
    //BLOCK VARIABLE GLOBAL
    ///////////////////
    var id_page = 1;

    ///////////////////
    //BLOCK FONCTIONS EVENEMENTS
    ///////////////////
    $(document).on('pageinit',function() {
        try {
            // Init commmun
            init_commun();

            // Init page
            var html = getHtmlSuiviKO(tabInfoLogin[0][0]);
            $("#main_content").prepend(html).trigger('create');

            afficheLive();
        } catch (er) {
            log(0, "ERROR(init_home):" + er.message);
        }
    });

    $(document).on('pageshow',function() {
        try {
            show_commun();
        } catch (er) {
            log(0, "ERROR(show):" + er.message);
        }
    });

    //Fin chargement page
    function OnLoad() {
        try {
            messagesShow();
        } catch (er) {
            log(0, "ERROR(OnLoad):" + er.message);
        }
    }
		
    ///////////////////
    //BLOCK FONCTIONS METIER
    ///////////////////
    function afficheLive() {
        try {
            var currentTime = new Date();
            var annee = currentTime.getFullYear();
            var mois = pad2(currentTime.getMonth()+1);
            var jour = pad2(currentTime.getDate());

            var strDate =  annee + '-' + mois + '-' + jour;

                            var tabLive = getTabLive(strDate);
            var htmlLive = getHtmlLive(tabLive);
                            $("#content_Live").html(htmlLive);
        } catch (er) {
            log(0, "ERROR(afficheLive):" + er.message);
        }
    }
		
    ///////////////////
    //BLOCK FONCTIONS BD
    ///////////////////

    ///////////////////
    //BLOCK FONCTIONS AFFICHAGE
    ///////////////////
    function getHtmlLive(tabLive) {
        try {
            var strResponse = "<br>";

            var labDate = getParameter("last_scan_inventaire_live");

            var strF = "";
            var strA = "";
            var strO = "";
            var strAJ = "";
            var strAM = "";
            var strFJ = "";
            var strFM = "";
            var strS = "";
            var strABS = "";
            var strR = "";
            var strSLAP1 = "";
            var strSLAP2 = "";
            var strSLAP34 = "";
            var strP1 = "";
            var strP2 = "";
            var strS3 = "";
            var strFA = "";

            var strRouge = "#B9121B";
            var strNoir = "#000000";
            var strVert = "#96CA2D";

            for (var indice in tabLive) {
                    if(tabLive[indice][0] == "F"){
                            strF = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "A"){
                            strA = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "O"){
                            strO = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "AM"){
                            strAM = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "FM"){
                            strFM = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "S"){
                            strS = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "ABS"){
                            strABS = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "R"){
                            strR = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "SLAP1"){
                            strSLAP1 = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "SLAP2"){
                            strSLAP2 = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "SLAP34"){
                            strSLAP34 = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "AJ"){
                            strAJ = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "FJ"){
                            strFJ = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "RM"){
                            strRM = tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "S3"){
                            strS3= tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "FA"){
                            strFA= tabLive[indice][1];
                    }

                    if(tabLive[indice][0] == "P1"){
                            try {
                                    strP1 += "<a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + tabLive[indice][1] + "\">" + tabLive[indice][2] + "</a><br>";
                            }catch (er){
                                    strP1 += "Aucun";
                            }
                    }

                    if(tabLive[indice][0] == "P2"){
                            try {
                                    strP2 += "<a target=\"_new\" href=\"http://10.197.68.30:4000/AutoDiseWeb/automate/popupModule.jsp?modType=SIG_SIG&modCode=" + tabLive[indice][1] + "\">" + tabLive[indice][2] + "</a><br>";
                            }catch (er){
                                    strP2 += "Aucun";
                            }
                    }
            }

            strResponse += "<center><table style=\"text-align: left; width: 100%; height: 100%;text-shadow: none;\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">";
            strResponse += "<tbody>";
            strResponse += "	<tr>";
            strResponse += "		<td style=\"width: 33%;\" bgcolor=\"#ABC8E2\"><center><font size=\"6\">A :  <b>" + strA + "<b/></font></center></td>";
            strResponse += "		<td style=\"width: 33%;\" bgcolor=\"#E1E6FA\"><center><font size=\"6\">A/J-1 : " + strAJ + "</font></center></td>";
            strResponse += "		<td style=\"width: 33%;\" bgcolor=\"#E1E6FA\"><center><font size=\"6\">A/M : " + strAM + "</font></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr>";

            var fontColor = "";
            if(parseInt(strF) < parseInt(strA)){
                    fontColor = " color=\""+strRouge+"\"";
            }else{
                    if(parseInt(strF) > parseInt(strA)){
                            fontColor = " color=\""+strVert+"\"";
                    }else{
                            fontColor = " color=\""+strNoir+"\"";
                    }
            }

            strResponse += "		<td bgcolor=\"#C4D7ED\"><center><font size=\"6\" "+fontColor+" >F : <b>" + strF + "(" + strFA + ")</b></font></center></td>";
            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><font size=\"6\">F/J-1 : " + strFJ + "</font></center></td>";

            var fontColor = "";
            if(parseInt(strFM) < parseInt(strAM)){
                    fontColor = " color=\""+strRouge+"\"";
            }else{
                    if(parseInt(strFM) > parseInt(strAM)){
                            fontColor = " color=\""+strVert+"\"";
                    }else{
                            fontColor = " color=\""+strNoir+"\"";
                    }
            }

            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><font size=\"6\" "+fontColor+" >F/M : " + strFM + "</font></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr>";

            if(strAM != "0"){
                    var txRetourMois = Math.round((parseInt(strRM)/parseInt(strAM))*100);
            }else{
                    var txRetourMois = 0;
            }
            var fontColor = "";
            if(txRetourMois < 10){
                    fontColor = " color=\""+strVert+"\"";
            }else{
                    if(txRetourMois > 10){
                            fontColor = " color=\""+strRouge+"\"";
                    }else{
                            fontColor = " color=\""+strNoir+"\"";
                    }
            }

            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><font size=\"6\" "+fontColor+" >Retour/Mois : " + txRetourMois + "%</font></td>";
            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><font size=\"6\">O : <b>" + strO + "<b/></font></center></td>";

            var fontColor = "";
            if((parseInt(strFM) - parseInt(strAM)) < 0){
                    fontColor = " color=\""+strRouge+"\"";
            }else{
                    if((parseInt(strFM) - parseInt(strAM)) > 0){
                            fontColor = " color=\""+strVert+"\"";
                    }else{
                            fontColor = " color=\""+strNoir+"\"";
                    }
            }

            var deltaPrevi =  (parseInt(strFM) - parseInt(strAM)) + (parseInt(strF) - parseInt(strA));

            strResponse += "		<td bgcolor=\"#E1E6FA\"><center><font size=\"6\" "+fontColor+" >Delta/M : " + (parseInt(strFM) - parseInt(strAM)) + "("+deltaPrevi+")</font></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr>";
            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><font size=\"6\">Stock : " + strS + "(" + strS3 + ")</font></center></td>";
            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><font size=\"6\">Absences : " + strABS + "</font></center></td>";
            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><font size=\"6\">Retour : " + strR + "</font></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr>";

            var fontColor = "";
            if(parseFloat(strSLAP1) < 90){
                    fontColor = " color=\""+strRouge+"\"";
            }else{
                    if(parseFloat(strSLAP1) > 90){
                            fontColor = " color=\""+strVert+"\"";
                    }else{
                            fontColor = " color=\""+strNoir+"\"";
                    }
            }

            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><font size=\"6\" "+fontColor+" >SLA P1 : " + strSLAP1 + "%</font></center></td>";

            var fontColor = "";
            if(parseFloat(strSLAP2) < 85){
                    fontColor = " color=\""+strRouge+"\"";
            }else{
                    if(parseFloat(strSLAP2) > 85){
                            fontColor = " color=\""+strVert+"\"";
                    }else{
                            fontColor = " color=\""+strNoir+"\"";
                    }
            }

            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><font size=\"6\" "+fontColor+" >SLA P2 : " + strSLAP2 + "%</font></center></td>";

            var fontColor = "";
            if(parseFloat(strSLAP34) < 80){
                    fontColor = " color=\""+strRouge+"\"";
            }else{
                    if(parseFloat(strSLAP34) > 80){
                            fontColor = " color=\""+strVert+"\"";
                    }else{
                            fontColor = " color=\""+strNoir+"\"";
                    }
            }

            strResponse += "	  <td bgcolor=\"#E1E6FA\"><center><font size=\"6\" "+fontColor+" >SLA P3/4 : " + strSLAP34 + "%</font></center></td>";
            strResponse += "	</tr>";
            strResponse += "	<tr>";
            strResponse += "	  <td bgcolor=\"#B9121B\"><center><font size=\"6\">P1 : " + strP1 + "</font></center></td>";
            strResponse += "	  <td bgcolor=\"#C03000\"><center><font size=\"6\">P2 : " + strP2 + "</font></center></td>";
            strResponse += "	  <td bgcolor=\"#E1E6FA\">&nbsp;</center></td>";
            strResponse += "	</tr>";
            strResponse += "</tbody>";
            strResponse += "</table></center>";
            strResponse += "<center>Les donn&eacute;es relev&eacute; &agrave;  : " + labDate + "</center>";
            strResponse += "<br>";

            return strResponse;
        } catch (er) {
            log(0, "ERROR(getHtmlLive):" + er.message);
        }
    }
  </script>
    
  </head>
  <body onload="OnLoad();">
    
	<!-- page -->
	<div data-role="page" data-title="Titre">
	
		<!-- /panel -->
		<div data-role="panel" id="mypanel" data-display="overlay" data-position="left">

		</div>
		<!-- /panel -->
	
		<!-- header -->
		<div data-role="header" data-position="fixed">
			<a href="#mypanel" data-role="button" data-icon="home" data-iconpos="notext">home</a>
			<h1 id="id_titre">titre</h1>
			<a href="javascript:window.location = ('./page_contact.html?mili='+getMilise());" data-role="button" data-icon="info" data-iconpos="notext">Contact</a>
		</div>
		<!-- /header -->

		<!-- content -->
		<div data-role="content" id="main_content">
		
			<div data-role="collapsible" data-collapsed="false" data-mini="true">
				<h3>Le live</h3>
				<div id="content_Live">Anomalie code E001</div>
			</div>
			
		</div>
		<!-- /content -->
		
		<!-- footer -->
		<div data-role="footer" data-position="fixed">
			<a data-role="button" data-icon="search" data-iconpos="notext" class="ui-btn-left" href="javascript:window.location = ('./page_faq.html?mili='+getMilise());">FAQ</a>
			<h1 id="id_affichageUser">User</h1>
			<a data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right" href="javascript:window.location = ('./page_sortie.html?mili='+getMilise());">Logout</a>
		</div>
		<!-- /footer -->
		
	</div>
	<!-- /page -->
</body>
</html>